package com.xinqi.modules.course.classmenu.controller.app;

import cn.hutool.core.collection.CollectionUtil;
import com.xinqi.common.base.enums.YesNoNumberEnum;
import com.xinqi.common.base.response.R;
import com.xinqi.common.core.enums.ClassMenuHideEnum;
import com.xinqi.modules.course.classmenu.dto.req.ClassMenuQueryDTO;
import com.xinqi.modules.course.classmenu.dto.rsp.ClassMenuResultDTO;
import com.xinqi.modules.course.classmenu.manager.ClassMenuManager;
import com.xinqi.modules.course.classmenu.param.req.ClassMenuUpdateParam;
import com.xinqi.modules.course.classmenu.service.ClassMenuService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * app课程中版块设置表(ClassMenu)表控制层
 *
 * @author liuxingxing
 * @since 2023-03-06 15:40:30
 */
@Tag(name = "App-班级菜单", description = "班级菜单")
@Validated
@RestController
@RequestMapping("/app/classMenu")
@RequiredArgsConstructor
public class AppClassMenuController {
    /**
     * 服务对象
     */
    private final ClassMenuService classMenuService;

    private final ClassMenuManager classMenuManager;


    /**
     * 查询未隐藏的所有班级菜单
     *
     * @return 所有数据
     */
    @GetMapping("/unhide/{classId}")
    public R<List<ClassMenuResultDTO>> selectUnhide(@PathVariable("classId") Long classId) {
        ClassMenuQueryDTO query = new ClassMenuQueryDTO();
        query.setClassId(classId);
        query.setHidden(ClassMenuHideEnum.NO_HIDE);
        query.setSort(YesNoNumberEnum.YES.getCode());
        return R.ok(this.classMenuService.findList(query));
    }

    /**
     * 查询隐藏的所有班级菜单
     *
     * @return 所有数据
     */
    @GetMapping("/hide/{classId}")
    public R<List<ClassMenuResultDTO>> selectHide(@PathVariable("classId") Long classId) {
        ClassMenuQueryDTO query = new ClassMenuQueryDTO();
        query.setClassId(classId);
        query.setHidden(ClassMenuHideEnum.HIDE);
        return R.ok(this.classMenuService.findList(query));
    }

    /**
     * 批量修改多条数据
     *
     * @param param 实体对象集合
     * @return 修改结果
     */
    @PostMapping("/updateBatch")
    public R<Void> updateBatch(@RequestBody ClassMenuUpdateParam param) {
        if (Objects.nonNull(param) && CollectionUtil.isNotEmpty(param.getClassMenus())) {
            this.classMenuManager.updateBatchById(param.getClassMenus());
        }
        return R.ok();
    }


}
